package com.qef.com.mmovie.mvp.interactor;

import com.orhanobut.logger.Logger;
import com.qef.com.mmovie.api.LaughImgServer;
import com.qef.com.mmovie.api.VideoListBean;
import com.qef.com.mmovie.entity.LaughImgEntity;
import com.qef.com.mmovie.entity.VVIdeoDetailsEntity;
import com.qef.com.mmovie.entity.VideoPlayEntity;
import com.qef.com.mmovie.net.IGetDataDelegate;
import com.qef.com.mmovie.utils.RxUtil;

import org.reactivestreams.Subscription;

import java.util.Calendar;
import java.util.Random;

import javax.inject.Inject;

import io.reactivex.FlowableSubscriber;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

import static android.R.attr.id;

/**
 * Created by guangjiego on 2017/3/31.
 */

public class LaughImgInteractor {
    private LaughImgServer laughImgServer;

    @Inject
    public LaughImgInteractor(LaughImgServer laughImgServer) {
        this.laughImgServer = laughImgServer;
    }

    public Disposable loadLaughImgList(int page, int size, int cateid, IGetDataDelegate<LaughImgEntity> iGetDataDelegate) {
        return laughImgServer.getLauthImgList(page, size, cateid).compose(RxUtil.<LaughImgEntity>background()).subscribe((Consumer<LaughImgEntity>) laughImgEntity -> iGetDataDelegate.getDataSuccess(laughImgEntity), new Consumer<Throwable>() {
            @Override
            public void accept(@NonNull Throwable throwable) throws Exception {
                throwable.printStackTrace();
                iGetDataDelegate.getDataError(throwable);
            }
        });
    }

    public Disposable loadLaughImgDetailsList(int postId, IGetDataDelegate<VVIdeoDetailsEntity> iGetDataDelegate) {

        return laughImgServer.getVVideTatils(postId).compose(RxUtil.background()).
                subscribe(iGetDataDelegate::getDataSuccess, throwable -> {
                    throwable.printStackTrace();
                    iGetDataDelegate.getDataError(throwable);
                });
    }

    public void test(int postId) {
        laughImgServer.getVVideTatils(postId).compose(RxUtil.background()).subscribe(new FlowableSubscriber<VVIdeoDetailsEntity>() {
            @Override
            public void onSubscribe(Subscription s) {
                Logger.d("xxxx1");
            }

            @Override
            public void onNext(VVIdeoDetailsEntity vvIdeoDetailsEntity) {
                Logger.d("xxxx2");
            }

            @Override
            public void onError(Throwable t) {
                Logger.d("xxxx3");
            }

            @Override
            public void onComplete() {
                Logger.d("xxxx4");
            }
        });

    }
}